Telegram Bots Utilities – examples: custom keyboard

Send a message with a custom keyboard

In this example I created a keyboard with 2 keys on the first row and 3 keys on the second row.
This is not the only possible configuration, you can create your custom layout simply creating an array of rows (and a row is a String array) and create your ReplyKeyboardMarkup.
Once created your ReplyKeyboardMarkup it will automatically create a keyboard with your desired layout.

Here is the code:

public static void main(String[] args) throws GettingUpdatesException, IOException {
    String yourToken = "YOUR TOKEN";
    TelegramBot b = new TelegramBot(yourToken);
    String[][] keys = new String[2][];
    keys[0] = new String[2];
    keys[0][0] = "Top-left";
    keys[0][1] = "Top-right";
    keys[1] = new String[3];
    keys[1][0] = "Bottom-left";
    keys[1][1] = "Bottom-center";
    keys[1][2] = "Bottom-right";
    ReplyKeyboardMarkup reply_markup = new ReplyKeyboardMarkup(keys);
    b.sendMessage("chat_id", "Custom keyboard Message", null, false, false, 0, reply_markup);</ul>
}

This is the result:

Example of customized keyboard on a telegram bot
Custom Keyboard
Previous Entries Telegram Bots Utilities - examples: send a photo Next Entries Telegram Bot Utilities - examples: Parsing text

4 thoughts on “Telegram Bots Utilities – examples: custom keyboard

    • leocus on said:

      Hi,
      At the moment this functionality is not implemented.
      Thanks for your feedback!
      I’ll fix it when I’ll have some spare time, but if you need it asap you can create a pull request on github!
      Bye!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.